package cj.web.vote.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.vote.domain.Song;

/**
 * 
 * @author 
 *
 */
@DAO
public interface SongDAO{
	
	@SQL("SELECT * FROM Song WHERE deleteFlag=1 #if(:t.name!=''){ AND name LIKE '%##(:t.name)%' } ORDER BY updateAT DESC LIMIT :t.start,:t.length ")
    List<Song> query(@SQLParam("t") Song song);
	
	@SQL("SELECT COUNT(1) FROM Song WHERE deleteFlag=1 #if(:t.name!=''){ AND name LIKE '%##(:t.name)%' } ")
    int querysize(@SQLParam("t") Song song);
    
    @SQL("SELECT * FROM Song WHERE id=:1")
    Song queryById(int id);
    
    @SQL("SELECT * FROM Song WHERE id = (SELECT songId FROM VoteSongRef WHERE id = :1 LIMIT 1)")
    Song queryByVoteSongId(int voteSongId);
    
    @SQL("INSERT INTO Song (name,description,imgURL,songURL,singer,university,colleage,deleteFlag,votePlus,createAT,updateAT) VALUES (:t.name,:t.description,:t.imgURL,:t.songURL,:t.singer,:t.university,:t.colleage,1,:t.votePlus,now(),now())")
    void create(@SQLParam("t") Song song);
	
	@SQL("UPDATE Song SET name=:t.name,description=:t.description,imgURL=:t.imgURL,songURL=:t.songURL,singer=:t.singer,university=:t.university,colleage=:t.colleage,votePlus=:t.votePlus,updateAT=now() WHERE id=:t.id")
    void update(@SQLParam("t") Song song);
    
    @SQL("UPDATE Song SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
}